<script setup>
import { useUserStore } from '@/stores/user'

const user = useUserStore()

function onLogout() {
  user.logout()
}
</script>

<template>
  <div class="container user">
    <template v-if="user.isLoggedIn">
      <h2>个人中心</h2>
      <div class="card profile">
        <div>用户ID：{{ user.profile?.id || '' }}</div>
        <div class="actions">
          <button class="btn" @click="onLogout">退出登录</button>
        </div>
      </div>
      <ul>
        <li><router-link to="/orders">订单</router-link></li>
        <li><router-link to="/user">账户信息</router-link></li>
      </ul>
    </template>
    <template v-else>
      <div class="card profile">请先前往 <router-link to="/login">登录</router-link></div>
    </template>
  </div>
</template>

<style scoped>
.profile { padding: 16px; }
ul { padding-left: 16px; }
li { margin: 6px 0; }
</style>


